

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import G1.DOC;

/**
 * Servlet implementation class detail
 */
@WebServlet("/detail")
public class detail extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public detail() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();


		String path = request.getParameter("path");
		path.replace("/", "\\");
		File files = new File(path);		
		try {
			DOC doc = new DOC(files);
			//out.print("result : ");
			/*out.print("<style type='text/css'>");
			out.print("div#wrapper {margin:20px 20px 0 20px;padding:20px;border:3px solid #000;box-shadow:3px 3px 5px silver;background-color:#fff;}");
			out.print("header {	margin:5px 0 20px 5px;	font:bold 20px/24px verdana;	color:#672c91;}");
			out.print("footer {	margin:10px 0 10px 5px;	font:normal 11px/20px verdana;	color:#672c91;	text-align:left;}");
			out.print("#wrapper span {	font:normal 16px/20px verdana;}");
			out.print("article {	text-align:justify;	font:normal 13px/20px helvetica;	color:#555;}");
			out.print("</style>");
			*/out.print("<div id='wrapper'><div id='header'>");
			out.print(doc.getTitle());
			out.print("</div><div id='author'>");
			out.println(doc.getAuthor());
			out.print("</div><div id='article'>");
			out.print(doc.getText());
			out.print("</div><div id='path'>");
			out.print(doc.getFileName());
			out.println("</div><div id='biblio'> [");
			out.print(doc.getBiblio());
			out.println("]</div>");	
			out.print("</div>");
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet( request,  response);
	}

}
